package com.lifeonwalden.game.mindustry.entity;

import com.lifeonwalden.game.mindustry.Global;
import com.lifeonwalden.game.mindustry.constant.*;
import com.lifeonwalden.game.mindustry.feature.Export;

import java.util.Optional;

public class Base extends StaticEntity {
    public Export[] exporters = new Export[4];

    public Base() {
        this.type = SurfaceType.Base;
        this.league = League.Pathfinder;
        this.hp = this.type.maxHp;
    }

    @Override
    public void doJobBefore() {
        for (Export exporter : exporters) {
            if (null != exporter) {
                Optional<ResourceType> resource = exporter.take();
                if (resource.isPresent()) {
                    switch (resource.get()) {
                        case Stone: {
                            Global.world.resourceWarehouse.stoneCount++;
                            break;
                        }
                    }
                }
            }
        }
    }

    @Override
    public void joinExporter(StaticEntity unit, Gate at) {
        this.exporters[at.ordinal()] = unit;
    }

    @Override
    public void unjoin(Gate at) {
        this.exporters[at.ordinal()] = null;
    }

    @Override
    public PorterType porterAt(Gate gate) {
        return PorterType.TAKER;
    }

    @Override
    public Surface copy(boolean deep) {
        Base newOne = (Base) super.copy(deep);
        if (!deep) {
            newOne.exporters = new Export[4];
        }
        return newOne;
    }
}
